<template>
  <div class="header-container">
    <div class="l-content">
      <el-button @click="handleMenu" icon="el-icon-menu" size="mini"></el-button>
      <!-- 面包屑 -->
      <el-breadcrumb separator="/">
        <el-breadcrumb-item v-for="item in tags" :key="item.path" :to="{ path: item.path }">{{ item.label }}
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="r-content">
      <el-dropdown @command="handleClick">
        <span class="el-dropdown-link">
<!--          <img class="user"-->
          <!--               v-bind:src="userInfo.avatarPath === null ? 'http://s2xnpq3z5.hb-bkt.clouddn.com/%E5%A4%B4%E5%83%8F%20%E5%95%86%E5%8A%A1%E7%94%B7%E5%A3%AB.png':userInfo.avatarPath"-->
          <!--               alt="">-->
          <img class="user"
               src="../assets/images/user-default.png"
               alt="">
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="userInfo">个人信息</el-dropdown-item>
          <el-dropdown-item command="logout">退出</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
      <img style="height: 40px;margin-left: 20px"
           src="../assets/img/sinotrans.png"
           alt="">
    </div>
    <el-dialog title="收货地址" :visible.sync="dialogFormVisible">
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {mapState} from 'vuex'
import Cookie from 'js-cookie'

export default {
  data() {
    return {
      userInfo: JSON.parse(localStorage.getItem('userInfo')),
      dialogFormVisible: false
    }
  },
  methods: {
    handleMenu() {
      // 相当于调用这个方法
      this.$store.commit('CollapseMenu');
    },
    handleClick(command) {
      if (command === 'logout') {
        window.location.reload(true);
        Cookie.remove('token');
        Cookie.remove('menu');
        localStorage.clear();
        this.$router.push('/login');
      } else {
        this.$router.push('/home')
      }
    }
  },
  computed: {
    ...mapState({
      tags: state => state.tab.tabList
    })
  }
}
</script>

<style lang="less" scoped>
.header-container {
  background-color: #015378;
  height: 60px;

  // 让按钮和头像居中
  display: flex;
  justify-content: space-between;
  align-items: center;
  // 不要紧贴边框
  padding: 0 20px;

  .el-dropdown-link {
    cursor: pointer;
    color: #409EFF;

    .user {
      width: 40px;
      height: 40px;
      // 50%变圆形
      border-radius: 50%;
    }

    .logoo {
      //width: 40px;
      height: 40px;
      /*      // 50%变圆形
            border-radius: 50%;*/
    }
  }
}

.l-content {
  display: flex;
  // 上下居中
  align-items: center;

  .el-breadcrumb {
    margin-left: 15px;

    // deep 强制生效
    /deep/ .el-breadcrumb__item {
      .el-breadcrumb__inner {
        &.is-link {
          color: #c2bfbf;
        }
      }

      &:last-child {
        .el-breadcrumb__inner {
          color: #fff;
        }
      }
    }
  }
}
</style>
